from rest_framework import serializers
from .models import Stock, UserStock, TradingSignal

class StockSerializer(serializers.ModelSerializer):
    class Meta:
        model = Stock
        fields = ['id', 'code', 'name', 'last_price', 'updated_at']

class UserStockSerializer(serializers.ModelSerializer):
    stock_detail = StockSerializer(source='stock', read_only=True)

    class Meta:
        model = UserStock
        fields = ['id', 'stock', 'stock_detail', 'created_at']

class TradingSignalSerializer(serializers.ModelSerializer):
    class Meta:
        model = TradingSignal
        fields = ['id', 'stock', 'signal_type', 'price', 'reason', 'created_at']

class StockScreenerSerializer(serializers.Serializer):
    industry = serializers.CharField(required=False, allow_null=True)
    market_value_min = serializers.FloatField(required=False, allow_null=True)
    market_value_max = serializers.FloatField(required=False, allow_null=True)
    turnover_rate_min = serializers.FloatField(required=False, allow_null=True)
    pe_min = serializers.FloatField(required=False, allow_null=True)
    pe_max = serializers.FloatField(required=False, allow_null=True) 